//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CCanvasText.cpp>
///	@path	~/src/graphics/canvas/
///	@date	2007/12/05
///	@desc	Static text on canvas.

#include "config/config.h"

#include "graphics/canvas/CCanvasText.h"

namespace xeres {

	IMPL_IOBJECT_CLASS( CCanvasText );

	// ctor
	CCanvasText::CCanvasText( RefWeak<IVar> var , RefWeak<IFont> font , int style , const Color4& color )
		: m_text( var )
		, m_font( font )
		, m_style( style )
		, m_rect( 0 , 0 , 0 , 0 )
		, m_color( color )
	{
	}

	// dtor
	CCanvasText::~CCanvasText( void )
	{
	}

	// Render
	void CCanvasText::Render( RenderContext& rc , RefWeak<ISprite> sprite )
	{
		WString str;
		if( !m_text->GetString( str ) )
			return;

		if( m_rect.width() == 0 || m_rect.height() == 0 )
		{
			m_rect.set( 0 , 0 , rc.ResX<int>() , rc.ResY<int>() );
		}
		int rect[4] = { m_rect.left() , m_rect.top() , m_rect.right() , m_rect.bottom() };
		sprite->DrawText( m_font , str , rect , m_style , m_color );
	}

	// SetRect
	void CCanvasText::SetRect( const Rect<int>& rect )
	{
		m_rect = rect;
	}

	// SetStyle
	void CCanvasText::SetStyle( int style )
	{
		m_style = style;
	}

	// SetColor
	void CCanvasText::SetColor( const Color4& color )
	{
		m_color = color;
	}

} // namespace xeres
